package com.evenmo.springjpademo.contrlller;

import com.evenmo.springjpademo.entity.User;
import com.evenmo.springjpademo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * This is Description
 *
 * @author moyongjun
 * @date 2019/12/03
 */
@Controller
@RequestMapping(value="/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/touser")
    public String toIndex(){
        return "user/touser";
    }


//    @RequestMapping(value="/show",method = RequestMethod.GET)//url后拼接参数
    @RequestMapping(value="/show/{name}",method = RequestMethod.GET)//Restful风格传参
    @ResponseBody
//    public User show(@RequestParam(value = "name") String name){//
        public User show(@PathVariable(value = "name") String name){//
        User user = userService.findByUserName(name);
        System.out.println("查询结果："+user);
        return user;
    }
}
